package com.ebt.m.wiki.adapter;

/**
 * Created by Damon.Han on 2016/6/12 0012.
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.config.CustomerConfig;
import com.ebt.m.data.bean.CommonCustomer;
import com.ebt.m.utils.EbtUtils;
import com.ebt.m.view.CircleImageView;

import java.util.List;


public class ListPopupWindowAdapter extends BaseAdapter {
    private List<CommonCustomer> mArrayList;
    private Context mContext;

    class ViewHolder {
        CircleImageView avatar;
        TextView sex;
        TextView age;
        TextView pro;
    }

    public ListPopupWindowAdapter(Context context, List<CommonCustomer> list) {
        this.mArrayList = list;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.wiki_item_common_customer, parent, false);
            holder.sex = (TextView) convertView.findViewById(R.id.sex);
            holder.age = (TextView) convertView.findViewById(R.id.age);
            holder.pro = (TextView) convertView.findViewById(R.id.pro);
            holder.avatar = (CircleImageView) convertView.findViewById(R.id.avatar);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (this.mArrayList != null) {
            final CommonCustomer itemName = this.mArrayList.get(position);
            holder.sex.setText(itemName.getSex() == 0 ? "女" : "男");
            holder.age.setText(itemName.getAge() + "岁");
            holder.pro.setText(EbtUtils.getCareerCategoryCn(itemName.getPro()));
            int resId = CustomerConfig.getPortraitResource(itemName.getSex(), itemName.getAge());
            holder.avatar.setImageResource(resId);
        }
        return convertView;

    }


}

